/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proms.net.modelo.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import proms.net.conexao.Conexao;
import proms.net.modelo.bean.*;

/**
 *
 * @author Harley
 */
public class ClienteProcessoDAO implements InterfaceClienteProcessoDAO {

    private Conexao conexao;

    public List<ClienteProcesso> getClientes() throws SQLException {
        System.out.println("entrou");
        List<ClienteProcesso> resultado = new ArrayList<ClienteProcesso>();
        ClienteProcesso clientePro = new ClienteProcesso();
        Connection con = Conexao.conecta();
        PreparedStatement stmt =
                    con.prepareStatement("SELECT cliente.cod_cliente, nome, n_processo, vara, acao  FROM cliente inner join processo on cliente.cod_cliente = processo.cod_cliente; ");


        try {
            ResultSet rs = stmt.executeQuery();
            while (rs.next()) {
                clientePro.setCli_codigo(rs.getString("cod_cliente"));
                clientePro.setNome(rs.getString("nome"));
                clientePro.setNumProcesso(rs.getString("n_processo"));
                clientePro.setVara(rs.getString("vara"));
                clientePro.setAcao(rs.getString("acao"));
                resultado.add(clientePro);

            }

            rs.close();
            stmt.close();
        } finally {
            Conexao.desconecta();
        }
        return resultado;
    }

    public List<ClienteProcesso> getListaCliente(ResultSet rs) throws SQLException {
        List<ClienteProcesso> resultCli = new ArrayList<ClienteProcesso>();

        while (rs.next()) {
            ClienteProcesso clientePro = new ClienteProcesso();

            clientePro.setNome(rs.getString("nome"));
            clientePro.setNumProcesso(rs.getString("bairro"));
            clientePro.setVara(rs.getString("celular"));
            clientePro.setAcao(rs.getString("cep"));

            resultCli.add(clientePro);

        }
        return resultCli;

    }
}
